<template>
	<view class="activity-list" :class="config.style">
		<view class="header">
			<text class="title">{{params.title}}</text>
			<text class="more" @click="goToMoreLink()">查看更多</text>
		</view>
		<view class="list" :class="params.rank == 1 ? 'rank1':'rank0'">
			<view :class="params.style == 0 ? 'style0':'style1'">
				<view class="item" v-for="(item,index) in params.list" :key="index" @click="goToDetailLink(item.id)">
					<view class="content">
						<view class="cover">
							<image mode="widthFix" :src="item.cover_200" @error="imageError" class="image"></image>
						</view>
						<view class="info">
							<view class="title text-ellipsis-2">{{item.title}}</view>
							<view class="description text-ellipsis" v-if="params.style != 1 && params.rank == 1">{{item.description}}</view>
							<view class="price" :class="!showSale?'hidden':''">￥ {{item.price == 0 ? '免费':item.price}}</view>
							<view class="exp-info">
								<view class="item view">
									<uni-icons type="eye" size="10" color="#999999"></uni-icons> 
									<text class="num">{{item.handling_view}}</text>
								</view>
								<view class="item sales">
									<uni-icons type="cart-filled" size="10" color="#999999"></uni-icons> 
									<text class="num">{{item.handling_sales}}</text>
								</view>
								<view class="item favorites">
									<uni-icons type="star" size="10" color="#999999"></uni-icons> 
									<text class="num">{{item.handling_sales}}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>

	export default {
		name: 'ActivityList',
		props: {
			title: {
				type: String,
				default: '线下活动列表'
			},
			type: {
				type: String,
				default: 'activity_list',
			},
			params: {
				type: Object,
				default: {},
			},
			config: {
				type: Object,
				default: {},
			},
		},
		data() {
			return {
				linkMoreParams: {},
				showSale: true,
			}
		},
		created() {
			//console.log(JSON.stringify(this.params))
			this.getLinkMoreParams();
			this.setShowSale();
		},
		methods: {
			/**
			 * IOS小程序判断显示购买价格及按钮
			 */
			setShowSale: function(){
				let systemInfo = uni.getStorageSync('systemInfo');
				this.showSale = true;
				//仅在微信小程序端执行
				// #ifdef MP-WEIXIN
				if(systemInfo.system.search("iOS") != -1){
					this.showSale = false;
					console.log('IOS')
				}
				// #endif
			},
			/**
			 * 获取链接参数
			 */
			getLinkMoreParams: function(){
				let linkMoreParams = {
					category_id : this.params.category_id,
					order_field : this.params.order_field,
					order_type: this.params.order_type,
				}
				//console.log(linkParams);
				this.linkMoreParams = linkMoreParams
			},
			/**
			 * 路由至页面
			 */
			goToMoreLink: function(){
				let base_url = siteInfo.siteroot + '?i=' + this.config.uniacid + '&c=entry&m=muu_activity'
				//let urlParams = this.util.urlEncode(params)
				//小程序内webview参数
				let params = {
					type : 'goods',
					web_url : encodeURIComponent(base_url  + '&do=activity&action=lists')
				};
				
				let paramsStr = JSON.stringify(params);//参数传递给小程序，所以这里需要转为字符串
				let url = '../detail/index?params=' + paramsStr
				console.log(url)
				//指定跳转地址
				uni.navigateTo({
				    url: url
				});
			},
			goToDetailLink: function(id){
				//小程序内webview参数
				let base_url = siteInfo.siteroot + '?i=' + this.config.uniacid + '&c=entry&m=muu_activity'
				let params = {
					type : 'goods',
					web_url : encodeURIComponent(base_url  + '&do=activity&action=detail&id=' + id)
				};
				
				let paramsStr = JSON.stringify(params);//参数传递给小程序，所以这里需要转为字符串
				
				let url = '../detail/index?params=' + paramsStr
				//console.log(url)
				//指定跳转地址
				uni.navigateTo({
				    url: url
				});
			},
			
		
		}
	}
</script>

<style lang="scss">
	.activity-list {
		margin: 5px;
		.header {
			display: flex;
			justify-content: space-between;
			padding: 10rpx;
			margin: 10rpx 0;
			.title {
				flex: 1;
				font-size: 32rpx;
				font-weight: 600;
				color: #000;
			}
			.more {
				color: #999;
				font-size: 24rpx;
			}
		}
		/*横排*/
		.list.rank0 {
			
			/*小图*/
			.style0{
				display: flex;
				flex-wrap: wrap;
				.item {
					width: 50%;
					.content {
						padding: 10rpx;
						.cover {
							border-radius: 10rpx;
							overflow: hidden;
							.image {
								width: 100%;
								display: block;
							}
						}
						.info {
							.title {
								margin-top: 16rpx;
								font-size: 28rpx;
								color: #000;
								font-weight: 600;
								height: 72rpx;
								line-height: 36rpx;
							}
							.description {
								color: #999;
								font-size: 24rpx;
							}
							.price {
								margin-top: 10rpx;
								font-size: 24rpx;
							}
							.exp-info {
								margin-top: 10rpx;
								color: #999;
								font-size: 24rpx;
								.item {
									display: inline;
									.num {
										margin: 0 10rpx;
									}
								}
							}
						}
					}
				}
			}
		}
		/*竖排*/
		.list.rank1 {
			/*小图*/
			.style0{
				display: flex;
				flex-wrap: wrap;
				.item {
					width: 100%;
					.content {
						padding: 10rpx;
						display: flex;
						flex-wrap: wrap;
						.cover {
							width: 280rpx;
							border-radius: 10rpx;
							overflow: hidden;
							.image {
								width: 100%;
								display: block;
							}
						}
						.info {
							padding-left: 20rpx;
							flex: 1;
							.title {
								font-size: 28rpx;
								color: #000;
								font-weight: 600;
								height: 72rpx;
								line-height: 36rpx;
							}
							.description {
								color: #999;
								font-size: 24rpx;
							}
							.price {
								margin-top: 10rpx;
								font-size: 24rpx;
							}
							.exp-info {
								margin-top: 10rpx;
								color: #999;
								font-size: 24rpx;
								.item {
									display: inline;
									.num {
										margin: 0 10rpx;
									}
								}
							}
						}
					}
				}
			}
		}
	}
	
	/*页面风格设计*/
	.Blue {
		.price {
			color: $Blue;
		}
	}
	.Green {
		.price {
			color: $Green;
		}
	}
	.LightRed {
		.price {
			color: $LightRed;
		}
	}
	.Orange {
		.price {
			color: $Orange;
		}
	}
	.LightPink {
		.price {
			color: $LightPink;
		}
	}
	.Magenta {
		.price {
			color: $Magenta;
		}
	}
</style>
